package csm.sql;

import java.sql.Array;
import java.sql.Blob;
import java.sql.CallableStatement;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.NClob;
import java.sql.PreparedStatement;
import java.sql.SQLClientInfoException;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.SQLXML;
import java.sql.Savepoint;
import java.sql.Statement;
import java.sql.Struct;
import java.util.ArrayList;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Executor;

/**
 *
 * @author seungmun
 * @since 2006.1.18.
 * @version
 * @see
 */
public class SmartConnection implements Connection
{
	private Connection cn;
	private ArrayList<Statement> statements = null;

	public SmartConnection(Connection cn)
	{
		this.cn = cn;
		this.statements = new ArrayList<Statement>();
	}

	public SmartConnection()
	{
		this.statements = new ArrayList<Statement>();
	}

	public void setConnection(Connection cn)
	{
		this.cn = cn;
	}

	public Statement createStatement() throws SQLException
	{
		Statement stmt = cn.createStatement();
		statements.add(stmt);
		return stmt;
	}

	public PreparedStatement prepareStatement(String sql) throws SQLException
	{
		PreparedStatement stmt = cn.prepareStatement(sql);
		statements.add(stmt);
		return stmt;
	}

	public CallableStatement prepareCall(String sql) throws SQLException
	{
		CallableStatement stmt = cn.prepareCall(sql);
		statements.add(stmt);
		return stmt;
	}

	public String nativeSQL(String sql) throws SQLException
	{
		return cn.nativeSQL(sql);
	}

	public void setAutoCommit(boolean autoCommit) throws SQLException
	{
		cn.setAutoCommit(autoCommit);

	}

	public boolean getAutoCommit() throws SQLException
	{
		return cn.getAutoCommit();
	}

	public void commit() throws SQLException
	{
		cn.commit();
	}

	public void rollback() throws SQLException
	{
		cn.rollback();

	}

	public void close() throws SQLException
	{
		for (Statement s : statements)
		{
			try
			{
				s.close();
			}
			catch (SQLException e)
			{
			}
		}
		cn.close();
	}

	public boolean isClosed() throws SQLException
	{
		return cn.isClosed();
	}

	public DatabaseMetaData getMetaData() throws SQLException
	{
		return cn.getMetaData();
	}

	public void setReadOnly(boolean readOnly) throws SQLException
	{
		cn.setReadOnly(readOnly);

	}

	public boolean isReadOnly() throws SQLException
	{
		return cn.isReadOnly();
	}

	public void setCatalog(String catalog) throws SQLException
	{
		cn.setCatalog(catalog);

	}

	public String getCatalog() throws SQLException
	{
		return cn.getCatalog();
	}

	public void setTransactionIsolation(int level) throws SQLException
	{
		cn.setTransactionIsolation(level);

	}

	public int getTransactionIsolation() throws SQLException
	{
		return cn.getTransactionIsolation();
	}

	public SQLWarning getWarnings() throws SQLException
	{
		return cn.getWarnings();
	}

	public void clearWarnings() throws SQLException
	{
		cn.clearWarnings();

	}

	public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException
	{
		Statement stmt = cn.createStatement(resultSetType, resultSetConcurrency);
		statements.add(stmt);
		return stmt;
	}

	public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException
	{
		PreparedStatement stmt = cn.prepareStatement(sql, resultSetType, resultSetConcurrency);
		statements.add(stmt);
		return stmt;
	}

	public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException
	{
		CallableStatement stmt = cn.prepareCall(sql, resultSetType, resultSetConcurrency);
		statements.add(stmt);
		return stmt;
	}

	public Map<String, Class<?>> getTypeMap() throws SQLException
	{
		return cn.getTypeMap();
	}

	public void setTypeMap(Map<String, Class<?>> arg0) throws SQLException
	{
		cn.setTypeMap(arg0);

	}

	public void setHoldability(int holdability) throws SQLException
	{
		cn.setHoldability(holdability);
	}

	public int getHoldability() throws SQLException
	{
		return cn.getHoldability();
	}

	public Savepoint setSavepoint() throws SQLException
	{
		return cn.setSavepoint();
	}

	public Savepoint setSavepoint(String name) throws SQLException
	{
		return cn.setSavepoint(name);
	}

	public void rollback(Savepoint savepoint) throws SQLException
	{
		cn.rollback(savepoint);

	}

	public void releaseSavepoint(Savepoint savepoint) throws SQLException
	{
		cn.releaseSavepoint(savepoint);

	}

	public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
	{
		Statement stmt = cn.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
		statements.add(stmt);
		return stmt;
	}

	public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
	{
		PreparedStatement stmt = cn.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability);
		statements.add(stmt);
		return stmt;
	}

	public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
	{
		CallableStatement stmt = cn.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability);
		statements.add(stmt);
		return stmt;
	}

	public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException
	{
		PreparedStatement stmt = cn.prepareStatement(sql, autoGeneratedKeys);
		statements.add(stmt);
		return stmt;
	}

	public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException
	{
		PreparedStatement stmt = cn.prepareStatement(sql, columnIndexes);
		statements.add(stmt);
		return stmt;
	}

	public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException
	{
		PreparedStatement stmt = cn.prepareStatement(sql, columnNames);
		statements.add(stmt);
		return stmt;
	}

	@Override
	public boolean isWrapperFor(Class<?> iface) throws SQLException
	{
		return cn.isWrapperFor(iface);
	}

	@Override
	public <T> T unwrap(Class<T> iface) throws SQLException
	{
		return cn.unwrap(iface);
	}

	@Override
	public Array createArrayOf(String arg0, Object[] arg1) throws SQLException
	{
		return cn.createArrayOf(arg0, arg1);
	}

	@Override
	public Blob createBlob() throws SQLException
	{
		return cn.createBlob();
	}

	@Override
	public Clob createClob() throws SQLException
	{
		return cn.createClob();
	}

	@Override
	public NClob createNClob() throws SQLException
	{
		return cn.createNClob();
	}

	@Override
	public SQLXML createSQLXML() throws SQLException
	{
		return cn.createSQLXML();
	}

	@Override
	public Struct createStruct(String arg0, Object[] arg1) throws SQLException
	{
		return cn.createStruct(arg0, arg1);
	}

	@Override
	public Properties getClientInfo() throws SQLException
	{
		return cn.getClientInfo();
	}

	@Override
	public String getClientInfo(String arg0) throws SQLException
	{
		return cn.getClientInfo(arg0);
	}

	@Override
	public boolean isValid(int arg0) throws SQLException
	{
		return cn.isValid(arg0);
	}

	@Override
	public void setClientInfo(Properties arg0) throws SQLClientInfoException
	{
		cn.setClientInfo(arg0);
	}

	@Override
	public void setClientInfo(String arg0, String arg1) throws SQLClientInfoException
	{
		cn.setClientInfo(arg0, arg0);
	}
/*
	@Override
	public void abort(Executor arg0) throws SQLException
	{
		cn.abort(arg0);

	}

	@Override
	public int getNetworkTimeout() throws SQLException
	{
		return cn.getNetworkTimeout();
	}

	@Override
	public String getSchema() throws SQLException
	{
		return cn.getSchema();
	}

	@Override
	public void setNetworkTimeout(Executor arg0, int arg1) throws SQLException
	{
		cn.setNetworkTimeout(arg0, arg1);
	}

	@Override
	public void setSchema(String arg0) throws SQLException
	{
		cn.setSchema(arg0);

	}*/

    @Override
    public void setSchema(String schema) throws SQLException
    {
        // TODO 자동 생성된 메소드 스텁

    }

    @Override
    public String getSchema() throws SQLException
    {
        // TODO 자동 생성된 메소드 스텁
        return null;
    }

    @Override
    public void abort(Executor executor) throws SQLException
    {
        // TODO 자동 생성된 메소드 스텁

    }

    @Override
    public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException
    {
        // TODO 자동 생성된 메소드 스텁

    }

    @Override
    public int getNetworkTimeout() throws SQLException
    {
        // TODO 자동 생성된 메소드 스텁
        return 0;
    }
}
